Skip to content

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Sep 30, 2025

Context: rust-lang/unsafe-code-guidelines#552

This experiments with a suggestion by @RustyYato to stop considering repr(C) types as 1-ZST for the purpose of repr(transparent). If we go with rust-lang/rfcs#3845 (or another approach for fixing repr(C)), they will anyway not be ZST on all targets any more, so this removes a portability hazard. Furthermore, zero-sized repr(C) structs may have to be treated as non-ZST for the win64 ABI (at least that's what gcc/clang do), so allowing them to be ignored in repr(transparent) types is not entirely coherent.

Turns out we already have an FCW for repr(transparent), namely #78586. This extends that lint to also check for repr(C).

TODO: update the lint name and wording to account for its extended scope.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 30, 2025

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@RalfJung
Copy link
Member Author

@bors try

rust-bors bot added a commit that referenced this pull request Sep 30, 2025
@rust-bors

This comment has been minimized.

@RalfJung RalfJung changed the title Repr c not zst repr(transparent): do not consider repr(C) types to be 1-ZST Sep 30, 2025
@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Sep 30, 2025

☀️ Try build successful (CI)
Build commit: 0de49ae (0de49ae9e81f9a1e7df6f0783824ce94ed18e8a9, parent: a2db9280539229a3b8a084a09886670a57bc7e9c)

@petrochenkov
Copy link
Contributor

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-147185 created and queued.
🤖 Automatically detected try build 0de49ae
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 30, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-147185 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-147185 is completed!
📊 8 regressed and 3 fixed (708741 total)
📊 1547 spurious results on the retry-regessed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-147185/retry-regressed-list.txt

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Oct 3, 2025
@RalfJung
Copy link
Member Author

RalfJung commented Oct 5, 2025

This found

  • a few cases of abi_stable-0.9.3, an outdated crate version where the lint probably has been fixed in more recent versions (and I highly doubt there's any repr(C) here, this is going to be about the non-exhaustive part of the lint)
  • dynamic_graph-0.1.5, a crate that didn't have any updates in 4 years, here, involving a use of generativity::Id. I don't actually understand why this happens as the Id type is repr(transparent) itself... but nothing here is repr(C) so this is also almost certainly about the non-exhaustive part of the lint, not the repr(C) part.

EDIT: It later got confirmed that these crates indeed already trigger the lint before this PR.

@RalfJung
Copy link
Member Author

RalfJung commented Oct 5, 2025

@bors try

rust-bors bot added a commit that referenced this pull request Oct 5, 2025
repr(transparent): do not consider repr(C) types to be 1-ZST
@rust-bors

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-bors
Copy link

rust-bors bot commented Oct 5, 2025

☀️ Try build successful (CI)
Build commit: e19b5cc (e19b5cc0f024358aaaecf2776a5291fa5a95b623, parent: e2c96cc06bdbdbc6f59c7551194d6a742260d6ff)

@RalfJung
Copy link
Member Author

RalfJung commented Oct 5, 2025

@craterbot
Copy link
Collaborator

👌 Experiment pr-147185-1 created and queued.
🤖 Automatically detected try build e19b5cc
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 5, 2025
@craterbot
Copy link
Collaborator

🚧 Experiment pr-147185-1 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-147185-1 is completed!
📊 6 regressed and 0 fixed (1534 total)
📊 90 spurious results on the retry-regessed-list.txt, consider a retry1 if this is a significant amount.
📰 Open the summary report.

⚠️ If you notice any spurious failure please add them to the denylist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

Footnotes

  1. re-run the experiment with crates=https://crater-reports.s3.amazonaws.com/pr-147185-1/retry-regressed-list.txt

@traviscross traviscross added P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. T-lang Relevant to the language team labels Oct 11, 2025
@tmandry
Copy link
Member

tmandry commented Oct 15, 2025

@rfcbot fcp merge

We talked about this in the lang meeting today. We agreed on these answers to #147185 (comment):

Should we phase out repr(transparent) ignoring repr(C) 1-ZST fields?

Yes, we should phase this out.

  • If yes, should we do this as part of the existing repr_transparent_external_private_fields lint (under some new name)? If it should be a new separate lint, please specify how exactly the two lints should behave. Specifically, which lints should fire for a repr(transparent) type that has a 1-ZST non-exhaustive field, a 1-ZST repr(C) field, and a non-ZST field? That type would only get rejected once we make both the non-exhaustive and the repr(C) restriction into hard errors, but we have no good way to fire a lint only if both lints are enabled, and the logic to disentangle these cases would become quite messy. It just doesn't seem worth it for something that so few people will even see.

We are fine with combining them. This is a pretty rare case so it doesn't seem worth splitting them.

  • What should the new lint (combined or not) be called?

The name we eventually settled on in the meeting was repr_transparent_non_zst_fields.

  • Should the lint fire in dependencies immediately? Even for the combined lint, crater found only two rarely-used old crates that would trigger it.

Given that this is so rare, we agreed to move immediately to deny-by-default, warn in deps.

@rust-rfcbot

This comment was marked as outdated.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 15, 2025
@tmandry

This comment was marked as outdated.

@rust-rfcbot

This comment was marked as outdated.

@rust-rfcbot rust-rfcbot removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 15, 2025
@tmandry tmandry removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 15, 2025
@tmandry
Copy link
Member

tmandry commented Oct 15, 2025

@rfcbot fcp merge

@rust-rfcbot
Copy link
Collaborator

rust-rfcbot commented Oct 15, 2025

Team member @tmandry has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.

@rust-rfcbot rust-rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 15, 2025
@tmandry tmandry added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Oct 15, 2025
@traviscross
Copy link
Contributor

@rfcbot reviewed

@RalfJung
Copy link
Member Author

RalfJung commented Oct 15, 2025 via email

@traviscross
Copy link
Contributor

The motivation is, e.g.:

If we go with rust-lang/rfcs#3845 (or another approach for fixing repr(C)), they will anyway not be ZST on all targets any more

I.e., these repr(C) types are (maybe) not guaranteed to be 1-ZSTs always everywhere. That's what we were trying to suggest in the name. We also had earlier considered repr_transparent_bad_fields.

@RalfJung
Copy link
Member Author

Given that rust-lang/rfcs#3845 hasn't been accepted yet, what should the lint say to explain that a repr(C) type is not a ZST? Something about future compiler versions?

@traviscross
Copy link
Contributor

traviscross commented Oct 15, 2025

Right. If we think we might change it in the future, that means we're not actually guaranteeing it today, as a language matter, from the perspective of our stability guarantees. So, e.g., maybe "this type may not be zero-sized on all targets in the future" or even "this type is not guaranteed to be zero-sized on all targets". I.e., maybe it happens to be true today, but in adding this lint, we're disclaiming this guarantee.

@rust-rfcbot rust-rfcbot added the final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. label Oct 15, 2025
@rust-rfcbot
Copy link
Collaborator

🔔 This is now entering its final comment period, as per the review above. 🔔

@rust-rfcbot rust-rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Oct 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. I-lang-nominated Nominated for discussion during a lang team meeting. I-lang-radar Items that are on lang's radar and will need eventual work or consideration. needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. P-lang-drag-1 Lang team prioritization drag level 1. https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-lang Relevant to the language team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants